//
//  FLLLoginViewController.m
//  FLLGodOfCookery
//
//  Created by LL.F on 16/8/29.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "FLLLoginViewController.h"
#import "FLLRegisterViewController.h"
#import "FLLFindPasswordViewController.h"
#import "FLLLoginAndRegisterTextField.h"
#import "FLLMacro.h"
#import "NSString+FLL_MD5.h"
#import "FLLLoginModel.h"
#import "LoginData.h"
#import "FLLMineViewController.h"
@interface FLLLoginViewController ()<UIGestureRecognizerDelegate>// 实现隐藏顶部navigationBar也有左滑返回的效果<1>
@property (weak, nonatomic) IBOutlet UIButton *ensureButton;
@property (weak, nonatomic) IBOutlet UIButton *agreeButton;
@property (weak, nonatomic) IBOutlet FLLLoginAndRegisterTextField *phoneNumberField;
@property (weak, nonatomic) IBOutlet FLLLoginAndRegisterTextField *passwordField;
@property (nonatomic, strong) FLLLoginModel *loginData;
@end

@implementation FLLLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.agreeButton.layer.borderWidth = 1;
    self.agreeButton.layer.borderColor = [UIColor blackColor].CGColor;
    
 
    /*
    // 设置button不可点 且变灰色!
    self.ensureButton.userInteractionEnabled = NO;
    self.ensureButton.alpha = 0.4;
     */
    
    self.navigationItem.title = @"登录";
    // 实现隐藏顶部navigationBar也有左滑返回的效果<2>
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
- (void)createPOSTRequest
{

    NSString *bodyString = [NSString stringWithFormat:@"device_id=190e35f7e04db0d27cf&device_name=SM-G9006W&password=%@&methodName=UserSignin&device_type=android&mobile=%@&version=4.40&", [self.passwordField.text stringWith32BitMD5Lower], self.phoneNumberField.text];
    
    [ZWYNetTool POST:@"http://api.izhangchu.com/" andBody:bodyString andBodyStyle: ZWYBodyString andHeader:@{@"Content-Type":@"application/x-www-form-urlencoded"} andResponse:ZWYJSON andSuccessBlock:^(id result) {
        
        NSLog(@"%@", result);
        self.loginData = [FLLLoginModel modelWithDic:result];
        FLLMineViewController *mineVC = [[FLLMineViewController alloc] init];
        mineVC.loginModel = self.loginData;
        [self.navigationController pushViewController:mineVC animated:NO];
        
    } andFailureBlock:^(NSError *error) {
        
    }];

}
// 隐藏顶部 navigationBar
// 隐藏顶部 navigationBar后就不会有左滑返回的效果了
- (void)viewWillAppear:(BOOL)animated
{
    
    self.navigationController.navigationBarHidden = YES;
    // 实现隐藏顶部navigationBar也有左滑返回的效果<3>
    [self.navigationController.view sendSubviewToBack:self.navigationController.navigationBar];
    self.tabBarController.tabBar.hidden = YES;
    
    
}
- (void)viewWillDisappear:(BOOL)animated
{
    
    self.navigationController.navigationBarHidden = NO;
    // 实现隐藏顶部navigationBar也有左滑返回的效果<4>
   
    [self.navigationController.view bringSubviewToFront:self.navigationController.navigationBar];
    self.tabBarController.tabBar.hidden = NO;
    
}
//// 隐藏底部 tabBar
//- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//{
//    
//    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
//    if (self) {
//        self.hidesBottomBarWhenPushed = YES;
//    }
//    return self;
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)didClickedRegisterButton:(id)sender
{
    FLLRegisterViewController *registerViewController = [[FLLRegisterViewController alloc] init];
    [self.navigationController pushViewController:registerViewController animated:YES];
}
// 点击确定按钮
- (IBAction)didClickedEnsureButton:(id)sender
{
    [self createPOSTRequest];
   
}
// 点击返回按钮
- (IBAction)didClickedBackButton:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];

}
// 点击忘记密码按钮
- (IBAction)didClickedForgetPasswordButton:(id)sender
{
    FLLFindPasswordViewController *findPassword = [[FLLFindPasswordViewController alloc] init];
    [self.navigationController pushViewController:findPassword animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
